<?php


namespace BoojasrFramework\Service;


use BoojasrFramework\Kernel;
use BoojasrFramework\Log\LoggerInterface;

class LoggerService
{
    /**
     * @return LoggerInterface|false|mixed
     */
    public function getLogger(){
        static $logObject;
        if ($logObject) {
            return $logObject;
        }
        try {
            $config = Kernel::getConfig();
            if (isset($config["logger"])&&isset($config["logger"]["class"])){
                $class = new \ReflectionClass($config["logger"]["class"]);
                $logObject = $class->newInstance();
                if ($logObject instanceof LoggerInterface){
                    return $logObject;
                }
            }
        }catch (\ReflectionException $e){
        }
        return false;
    }

    public function info($content){
        $this->getLogger()->info($content);
    }

    public function error($content){
        $this->getLogger()->error($content);
    }

    public function warning($content){
        $this->getLogger()->warning($content);
    }
}
